let vm = new Vue({
    el: "#app",
    data: {
        checkCode: "",
        user: {},
        tag: false
    },
    methods: {
        checkEmail: function (e) {
            if (this.user.email != undefined && this.user.email != "") {
                axios({
                    url: `/user/checkEmail/${this.user.email}`
                }).then(res => {
                    if (res.data.flag) {
                        this.tag = false;
                        layer.msg('邮箱不存在');
                        $(e.target).addClass('input-error');
                    } else {
                        this.tag = true;
                        $(e.target).removeClass('input-error');
                    }
                });
            }
        },
        sendCode: function () {
            if (this.user.email != undefined && this.user.email != "" && this.tag) {
                axios({
                    method: 'post',
                    url: `/user/sendCode/${this.user.email}`
                }).then(res => {
                    layer.msg(res.data.message);
                });
            } else {
                layer.msg("邮箱有误");
            }
        },
        submit: function () {
            if (this.user.email != "" && this.user.password != "" && this.tag) {
                axios({
                    method: 'post',
                    url: `/user/forget/${this.checkCode}`,
                    data: this.user
                }).then(res => {
                    if (res.data.flag) {
                        layer.msg(res.data.message + ",两秒后跳回登录页面。");
                        setInterval(() => {
                            location.href = "/index.html"
                        }, 2000);
                    } else {
                        layer.msg(res.data.message);
                    }
                });
            } else {
                layer.msg("输入有误");
            }
        }
    }
})